﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.Rivyer.BLL;
using Com.Rivyer.Model;

namespace Com.Rivyer.BLL
{
    public class userqueryinfoBll
    {
        private readonly DAL.userDal userdal = new DAL.userDal();
        private readonly DAL.userloginlogDal loginlogdal = new DAL.userloginlogDal();
        private readonly DAL.useroperatelogDal operatelogdal = new DAL.useroperatelogDal();
        public Model.userqueryinfoModel getModel(string username)
        {
            System.Data.DataSet operateds = operatelogdal.GetList(1, string.Format("username='{0}'", username), "id desc");
            Model.userModel usermodel = userdal.GetModel(username);
            Model.userqueryinfoModel queryinfomodel = new userqueryinfoModel();
            queryinfomodel.createdate = usermodel.createdate;
            queryinfomodel.username = username;
            if (loginlogdal.GetList(2,string.Format("username = '{0}'",username),"id desc").Tables[0].Rows.Count == 2)
            {
                queryinfomodel.latestlogin = DateTime.Parse(loginlogdal.GetList(2, string.Format("username = '{0}'", username), "id desc").Tables[0].Rows[1]["logintime"].ToString());
            }
            if (operateds.Tables[0].Rows.Count == 1)
            {
                queryinfomodel.latestoperate = new Maticsoft.Common.Operatelog().getOperatelog(operateds.Tables[0].Rows[0]["username"].ToString(), DateTime.Parse(operateds.Tables[0].Rows[0]["createdate"].ToString()), operateds.Tables[0].Rows[0]["operation"].ToString(), operateds.Tables[0].Rows[0]["description"].ToString());
            }
            else
            {
                queryinfomodel.latestoperate = "没有记录!";
            }
            
            queryinfomodel.logincount=loginlogdal.GetRecordCount(string.Format("username='{0}'",username));
            return queryinfomodel;
        }
    }
}
